
###########################
###########################
## Hungary pilot list experiments
## Mares & Young (2017)
###########################
###########################


rm(list = ls())


## set working directory

setwd('/Users/Lauren/Dropbox/Hungary_All/Analysis/core_rep_pkg')


## call packages - use install.packages() if necessary

library(Hmisc)
options(digits = 2)


## set functions
replace_NA <- function(data, varnames, NAvals) {
  numvars <- length(varnames)
  numNA <- length(NAvals)
  data <- as.data.frame(data)
  for (i in 1:numvars){
    varname <- varnames[i]
    for (j in 1:numNA) {
      data[,varname] <- ifelse(data[,varname]==NAvals[j], NA, data[,varname])
    }
  }
  return(data)
}


## read in data

dat1 <- read.csv("data/pretest_type1.csv")
dat2 <- read.csv("data/pretest_type2.csv")


#####
## clean data
#####

## rename items
colnames(dat1)[which(colnames(dat1)=="q1.10")] <- "mlend_2"
colnames(dat1)[which(colnames(dat1)=="q1.20")] <- "mlend_4"
colnames(dat1)[which(colnames(dat1)=="q1.13")] <- "mayfav_2"
colnames(dat1)[which(colnames(dat1)=="q1.11")] <- "maypres_1"
colnames(dat1)[which(colnames(dat1)=="q1.09")] <- "vbuy_2"
colnames(dat1)[which(colnames(dat1)=="q1.12")] <- "welfare_1"

colnames(dat2)[which(colnames(dat2)=="q2.08")] <- "mayfav_3"
colnames(dat2)[which(colnames(dat2)=="q2.09")] <- "maypres_2"
colnames(dat2)[which(colnames(dat2)=="q2.07")] <- "mlend_3"
colnames(dat2)[which(colnames(dat2)=="q2.18")] <- "vbuy_1"
colnames(dat2)[which(colnames(dat2)=="q2.21")] <- "welfare_2"

## replace NAs
dat1 <- replace_NA(dat1, 
                   c('mlend_2', 'mlend_4', 'mayfav_2', 'maypres_1', 'vbuy_2', 'welfare_1'), 
                   c('88', '99'))
dat2 <- replace_NA(dat2, 
                   c('mayfav_3', 'maypres_2', 'mlend_3', 'vbuy_1', 'welfare_2'), 
                   c('88', '99'))


#####
## test prevalence across wordings
#####

prev <- function(x) { table(x)/length(na.omit(x)) }


## general favors from mayor
p <- data.frame('Q'=c('Q1', 'Q2'), 'prop'=rep(NA,2))

p[1,'prop'] <- prev(dat1$mayfav_2)[1]
  # "The mayor’s men have offered to help me get some benefits in exchange for my vote"
p[2,'prop'] <- prev(dat2$mayfav_3)[1]
  # "I expect to get a favor from the mayor’s men if I vote for the candidate he likes"

    # mayfav_3 gets us higher results - it is less direct ie no "in exchange for my vote"
    # mayfav_3 also has some people saying they don't know or refuse

p$Q <- c(
"The mayor's 
men have 
offered to 
help me get 
some benefits 
in exchange 
for my vote.",
"I expect to 
get a favor 
from the 
mayor's men 
if I vote for 
the candidate 
he likes.")

pdf('graphs/pilot/favor.pdf')
ggplot(p, aes(Q, prop)) +
  geom_bar(stat="identity", position='dodge', fill='darkgreen') +
  scale_y_continuous(name = 'Proportion', limits=c(0,1)) +
  scale_x_discrete(name = 'Question Wording') +
  theme_minimal() +
  theme(text = element_text(size = 20),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) 
dev.off()

## general pressure from mayor
p[1,'prop'] <- prev(dat1$maypres_1)[1]
  # "The mayor’s men pressured me to support a particular candidate"
p[2,'prop'] <- prev(dat2$maypres_2)[1]
  # "One of the mayor’s people pressured me to vote for someone"

p$Q <- c(
"The mayor's 
men pressured 
me to support 
a particular 
candidate.",
"One of the 
mayor's people 
pressured me 
to vote for 
someone.")

pdf('graphs/pilot/gen_pressure.pdf')
ggplot(p, aes(Q, prop)) +
  geom_bar(stat="identity", position='dodge', fill='red') +
  scale_y_continuous(name = 'Proportion', limits=c(0,1)) +
  scale_x_discrete(name = 'Question Wording') +
  theme_minimal() +
  theme(text = element_text(size = 20),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) 
dev.off()

    # very small difference between maypres_1 and maypres_2 but 2 is slightly softer
    # maypres_2 gets much higher incidence


## vote buying

p[1,'prop'] <- prev(dat1$vbuy_2)[1]
  # "I will vote for someone because I received money, gifts, or food"
p[2,'prop'] <- prev(dat2$vbuy_1)[1]
  # "Someone offered me a gift, drinks or a meal for my vote."

p$Q <- c(
"I will vote for 
someone 
because 
I received 
money, gifts, 
or food.",
"Someone 
offered me 
a gift, drinks 
or a meal for 
my vote.")

pdf('graphs/pilot/vote_buying.pdf')
ggplot(p, aes(Q, prop)) +
  geom_bar(stat="identity", position='dodge', fill='lightgreen') +
  scale_y_continuous(name = 'Proportion', limits=c(0,1)) +
  scale_x_discrete(name = 'Question Wording') +
  theme_minimal() +
  theme(text = element_text(size = 20),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) 
dev.off()

    # no diff between vote buying questions
    # very low incidence

## welfare coercion
p[1,'prop'] <- prev(dat1$welfare_1)[1]
  # "I am worried that someone in my family might lose my munanelkuli sagely based on how we vote"
p[2,'prop'] <- prev(dat2$welfare_2)[1]
  # "Someone in my family might lose the munanelkuli sagely because of how we vote"

p$Q <- c(
"I am worried 
that someone 
in my family 
might lose 
the workfare
benefit based
on how we vote.",
"Someone in my 
family might 
lose the workfare
benefit because 
of how we vote.")

pdf('graphs/pilot/welf_pressure.pdf')
ggplot(p, aes(Q, prop)) +
  geom_bar(stat="identity", position='dodge', fill='darkred') +
  scale_y_continuous(name = 'Proportion', limits=c(0,1)) +
  scale_x_discrete(name = 'Question Wording') +
  theme_minimal() +
  theme(text = element_text(size = 20),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) 
dev.off()

    # welfare_1 slightly less DK and slightly higher incidence
    # welfare_1 includes "I am worried that..." - perhaps people don't ahve proof but have a feeling of fear


## moneylender coercion
p <- data.frame('Q'=c('Q1', 'Q2', 'Q3'), 'prop'=rep(NA,3))

p[1,'prop'] <- prev(dat1$mlend_2)[1]
  # "I am worried about what my lender will do if I vote for a candidate he doesn’t like"
p[2,'prop'] <- prev(dat2$mlend_3)[1]
  # "I am worried that I will owe more money to my lender if I vote for a candidate he doesn’t like"
p[3,'prop'] <- prev(dat1$mlend_4)[1]
  # "I might owe more money to my lender if I vote for a candidate he doesn’t like"

p$Q <- c(
"I am worried 
about what my 
lender will do 
if I vote for a 
candidate he 
doesn't like",
"I am worried 
that I will owe 
more money to my 
lender if I vote
for a candidate 
he doesn't like",
"I might owe more 
money to my  
lender if I vote  
for a candidate  
he doesn't like")

pdf('graphs/pilot/lender_pressure.pdf')
ggplot(p, aes(Q, prop)) +
  geom_bar(stat="identity",position='dodge', fill='darkorange') +
  scale_y_continuous(name = 'Proportion', limits=c(0,1)) +
  scale_x_discrete(name = 'Question Wording') +
  theme_minimal() +
  theme(text = element_text(size = 18),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) 
dev.off()

    # mlend_2 has way higher DK - the question is more menacing "what my lender might do"
    # this seems to be the best case for a list experiment
    # mlend_3 which also includes "I am worried" gets highest positive response
    # moneylender coercion is again super high - 38% yes on mlend_3

cor(dat1$mlend_2, dat1$mlend_4, use = 'complete.obs')
table(dat1$mlend_2, dat1$mlend_4)

